package hot100.logos41To50;

import hot100.datastruct.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author logos
 * date 2025/7/14 12:15
 * @version v1.0
 * @Package hot100.logos41To50
 */
public class logos45 {

    /**
     * 45. 二叉树的右视图
     * https://leetcode.cn/problems/binary-tree-right-side-view/?envType=study-plan-v2&envId=top-100-liked
     */
    class Solution {
        public List<Integer> rightSideView(TreeNode root) {
            List<Integer> ans = new ArrayList<>();
            dfs(root, 0, ans);
            return ans;
        }

        private void dfs(TreeNode root, int depth, List<Integer> ans) {
            if (root == null) {
                return ;
            }
            if (depth == ans.size()) {
                ans.add(root.val);
            }
            dfs(root.right, depth + 1, ans);
            dfs(root.left, depth + 1, ans);
        }
    }
}
